package com.gukun.springboot.tdengine.dto;

import cn.hutool.core.util.ArrayUtil;

public class CreateTableDto {
    /**
     * 表前缀
     */
    private String prefix;
    /**
     * 建表数量
     */
    private Integer count;
    /**
     * 建表比例
     */
    private String ratio;

    private  String[] ratioArray;

    private Integer ratioSum;
    /**
     * 建表起开始索引
     */
    private Integer index;

    private TDengineConfigDto tDengineConfigDto;

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getRatio() {
        return ratio;
    }

    public void setRatio(String ratio) {
        this.ratio = ratio;
    }

    public String[] getRatioArray() {
        if(ArrayUtil.isEmpty(this.ratioArray)){
            this.ratioArray = this.ratio.split(":");
        }
        return ratioArray;
    }


    public Integer getRatioSum() {
        if(this.ratioSum == null){
            this.ratioSum = getFloatRatioCount() + getDoubleRatioCount() + getIntRatioCount() + getBoolRatioCount();
        }
        return ratioSum;
    }
    //比例顺序按照  float:double:int:bool
    //获取对应的比例具体数值
    public int getFloatRatioCount() {
        return Integer.parseInt(getRatioArray()[0]);
    }

    public int getDoubleRatioCount(){
        return Integer.parseInt(getRatioArray()[1]);
    }

    public int getIntRatioCount(){
        return Integer.parseInt(getRatioArray()[2]);
    }

    public int getBoolRatioCount(){
        return Integer.parseInt(getRatioArray()[3]);
    }

    public int getTableCount(int ratioCount){
        return (int) Math.ceil((this.count * (ratioCount*1.0 / this.getRatioSum())));
    }

    //获取float表的数量
    public int getFloatTableCount(){
        return this.getTableCount(this.getFloatRatioCount());
    }

    public int getDoubleTableCount(){
        return this.getTableCount(this.getDoubleRatioCount());
    }

    public int getIntTableCount(){
        return this.getTableCount(this.getIntRatioCount());
    }

    public int getBoolTableCount(){
        return this.getTableCount(this.getBoolRatioCount());
    }


    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public TDengineConfigDto gettDengineConfigDto() {
        return tDengineConfigDto;
    }

    public void settDengineConfigDto(TDengineConfigDto tDengineConfigDto) {
        this.tDengineConfigDto = tDengineConfigDto;
    }
}
